﻿#pragma once

#include <GraphicsBaseItem.h>
#include <QDateTime>

class GraphicsScene;
class MoveStrategy;
class GraphicsTextItem;

class GraphicsImageItem : public GraphicsBaseItem
{
	Q_OBJECT
public:
	GraphicsImageItem(GraphicsBaseItem* parent = nullptr, GraphicsScene* scene = nullptr);

	~GraphicsImageItem();

	void setImage(const QImage& image = QImage());

	// 以fitFactor的比例适配
	void fitImageToSize(qreal fitFactor = 0.8, bool isScale = true);

	virtual void initGraphics()override;

	// 获取背景图片
	QImage getImage();
private:
	void init();
	void createTextItem();
private slots:
	void onMaskChanged();
protected:
	virtual void operationDone(GraphicsPinkItemType type, const QPointF& mousePoint)override;

	virtual void scaleGraphics(GraphicsPinkItemType type, const QPointF& delta)override;

	virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr)override;

	virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event)override;
private:
	// 抠图后的图片
	QImage m_cutoutImage;
	// 固定尺寸
	QSizeF m_size = QSizeF(440, 440);
	// 文案提示
	GraphicsTextItem* m_textItem = nullptr;
	// 记录文案显示时间
	QDateTime m_textShowTime;
};
